home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 August: Tool Chest / Dev.CD Aug 98 TC.toast / Tool Chest / Testing & Debugging / Mac OS Development Toolkit / Automation Essentials 2.3.0 / Host Automation Folder / SPEC Libs / Palette.Lib < prev    next >
Encoding:
Text File  |  1998-03-19  |  24.8 KB  |  637 lines  |  [TEXT/MPS ]

  1. #
  2. # ****************************************************************************
  3. #
  4. #    File Name:        Palette.Lib
  5. #
  6. #    Contains:    xxx put contents here xxx
  7. #
  8. #    Written by:    KTA, KL, ML, GS et al
  9. #
  10. #    Copyright:    © 1993-1996 by Apple Computer, Inc., all rights reserved.
  11. #
  12. # ****************************************************************************
  13. #            C h a n g e        H i s t o r y (most recent first):
  14. # ****************************************************************************
  15. #
  16. #        Vers      Date        Author        Description
  17. #        ----    --------    ------    ---------------------------------------------
  18. #    1.0.113>      2/8/96    JC        Changed all window .r (Rect) traits to .b (bound) traits and
  19. #                                    changed any window insets to reflect new bound rect.
  20. #    1.0.112>    12/19/95    ML        add global hook to SelFromMenuItemPopUp and SelFromPopUp
  21. #    .0.111+>    12/19/95    ML        add global hook to
  22. #    1.0.111>    12/18/95    ML        SelFromMenuItemPopUp -  Move to left first, then top of palette
  23. #                                    to maintain selection
  24. #    .0.110+>    12/18/95    ML        
  25. #    1.0.110>     12/8/95    ML        CalcOffset - revise for single row of tools
  26. #    1.0.19+>     12/8/95    ML        
  27. #    <1.0.19>     12/6/95    ML        CalcOffset - card theRect s/b <4
  28. #    1.0.18+>     12/6/95    ML        CalcOffset - card theRect s/b <4
  29. #    <1.0.18>    11/13/95    ML        CalcOffset - add support for left margin         in kPalWind
  30. #    1.0.17+>    11/13/95    ML        CalcOffset - add support for left margin in kPalWind
  31. #    <1.0.17>    11/10/95    ML        Tool Structure accessors - added support for gradient,
  32. #                                    background color, text color, and pen patterns
  33. #    1.0.16+>     11/9/95    ML        support for more palettes
  34. #    <1.0.16>     11/9/95    ML        SelFromMenuItemPopUp, SelFromPopUp - removed mismatched else
  35. #    1.0.15+>     11/9/95    ML        Mismatched else
  36. #    <1.0.15>    12/12/94    ML        removed gTargetcheck
  37. #    1.0.14+>    12/12/94    ML        removed gTargetcheck
  38. #    <1.0.14>    11/29/94    ML        Added Support for exception handling
  39. #    1.0.13+>    11/29/94    ML        Added Support for exception handling
  40. #    <1.0.13>     9/19/94    KTA        SelFromPopUp(), SelFromMenuItemPopUp() - Turn gTargetCheck off
  41. #                                    so won't match the target when mouseDown.
  42. #    <1.0.12>     9/19/94    KTA        CalcOffset() - Added a rewrite by Michael Press plus a fix when
  43. #                                    a single column of tools for kPalDocWind,kPalWind.
  44. #    <1.0.11>      5/2/94    KTA        Removed all references to kPullOffPal, kScrollPal.
  45. #    <1.0.10>     3/17/94    KTA        Added support for kMenuItemPopUpPal palettes.
  46. #     <1.0.9>     3/16/94    KTA        New TCS set - kTCSetSelectFromPalette.
  47. #     <1.0.8>     3/16/94    KTA        Moved TCS calls to selection routines.
  48. #     <1.0.7>    11/19/93    NAGA        modify TCS format
  49. #     <1.0.6>     8/25/93    KTA        Added support for parity checking the TCS stack.
  50. #     <1.0.5>      8/3/93    KTA        SelFromCoord() - There was no returnVal for absolute coordinate
  51. #                                    moves.
  52. #     <1.0.4>      6/8/93    NAGA        unmark tasks that are not published
  53. #     <1.0.3>     5/21/93    NAGA        Adding header and porting old files to follow new standards
  54. #
  55. # ****************************************************************************
  56. #
  57.  
  58. ########################################################################
  59. #                            External libraries 
  60. #=======================================================================
  61. Libraries  "TCS.Lib","Output.Lib","UserInterface.Lib", "ExceptionHandling.lib";
  62.  
  63. #########################################################################
  64. #########################################################################
  65. #                            Palette Structure Accessors()
  66. #========================================================================
  67. # Author:        DM 
  68. # Description:    These functions access the data in an palette data struct
  69. # Parameters:    palStruct
  70. # Returns:        the requested data element or list
  71. #========================================================================
  72. # History:
  73. #
  74. #########################################################################
  75. task GetPalRect(palStruct)         begin return( palStruct[1] );    end;
  76. task GetPalType(palStruct)         begin return( palStruct[2] );    end;
  77. task GetPalMatrixSize(palStruct) begin return( palStruct[3] );    end;
  78. task GetPalOffsets(palStruct)     begin return( palStruct[4] );    end;
  79. #task GetPalHeaderSize(palStruct) begin return( palStruct[5] );    end;    # Not used
  80. #task GetPalOnDesk(palStruct)         begin return( palStruct[6] );    end;    # Not used
  81.  
  82. task InsertPalRect(rect, pS)        begin return( replace(rect, 1, pS ));    end;
  83. task InsertPalOnDesk(onDesk, pS)    begin return( replace(onDesk, 6, pS ));end;
  84.  
  85.  
  86. #########################################################################
  87. #                            Tool Structure Accessors()
  88. #========================================================================
  89. # Author:        DM 
  90. # Description:    These functions access the data in an tool data struct
  91. # Parameters:    elemStruct
  92. # Returns:        the requested data element or list
  93. #========================================================================
  94. # History:
  95. # ML    11/10/95    Added support for gradients, background colors, text colors,
  96. #                    and pen patterns
  97. #########################################################################
  98. ## elemStruct is the data structure that completely specifies tools
  99. ##            elemStruct    {
  100. ##                ElemNum
  101. ##                PalNum
  102. ##                ElemName
  103. ##                ElemType    - kClick := move-click 
  104. ##                                        (Pointlist is single set of points)
  105. ##                            - kDrag     := move-pressmouse-move-releasMouse 
  106. ##                                        (Pointlist is two set of points)
  107. ##                            == Pointlist is defined by Global gNumPoints ==
  108. ##                            - kMultiDrag := move-pressmouse-move-move…releasMouse
  109. ##                            - kMultiClick:= move-click-move-click-move…
  110. ##                            - kMultiClickDragTool := move-pressmouse-move-releasMouse-pressmouse-move-releasMouse…
  111. ##                            
  112. ##                elemDblClk  - Flag to doulble click when finished
  113. ##                            - 0 := No DoubleClick
  114. ##                            - 1 := DoubleClick
  115. ##
  116. ##                SetAttribute  - Flag indicating when to set attributes
  117. ##                            - 0 := No attributes to set
  118. ##                            - 1 := Set attribute before drawing object
  119. ##                            - 2 := Set attribute after drawing object
  120. ##                            - "str" := Type <'Str'> after drawing object (texttool)
  121. ##            }
  122. ##        Defined ElemTypes:
  123. ##                 
  124. #########################################################################
  125. ##    Example: global CharTool    :=     { ElemNum, PalNum,"ElemName", ElemType,    elemDblClk};
  126. ##             global CharTool    :=     { 17     , 1     ,"Char"    , kClick  ,    0          };
  127. #########################################################################
  128. task GetElemNum(elemStruct)         begin return( elemStruct[1] );    end;
  129. task GetPalNum(elemStruct)             begin return( elemStruct[2] );    end;
  130. task GetElemName(elemStruct)        begin return( elemStruct[3] );    end;
  131. task GetElemType(elemStruct)         begin return( elemStruct[4] );    end;
  132. task GetElemDblClk(elemStruct)        begin return( elemStruct[5] );    end;
  133.  
  134. task GetAttributes(elemStruct)        begin return( elemStruct[6] );    end;
  135. task GetSetAttribute(elemStruct)    begin return( elemStruct[6][1] );    end;
  136. task GetPatternFlag(elemStruct)        begin return( elemStruct[6][2] );    end;
  137. task GetLineFlag(elemStruct)        begin return( elemStruct[6][3] );    end;
  138. task GetColorFlag(elemStruct)        begin return( elemStruct[6][4] );    end;
  139. task GetGradientFlag(elemStruct)        begin return( elemStruct[6][5] );    end;
  140. task GetBackgroundColorFlag(elemStruct)        begin return( elemStruct[6][6] );    end;
  141. task GetTextColorFlag(elemStruct)        begin return( elemStruct[6][7] );    end;
  142. task GetPenPatternFlag(elemStruct)        begin return( elemStruct[6][8] );    end;
  143.  
  144. task InsertElemNum(eNum, tS)         begin return( replace( eNum, 1, tS ));    end;
  145. task InsertPalNum(pNum, tS)         begin return( replace( pNum, 2, tS ));    end;
  146. task InsertElemName(eNam, tS)        begin return( replace( eNam, 3, tS ));    end;
  147. task InsertElemType(eTyp, tS)         begin return( replace( eTyp, 4, tS ));    end;
  148. task InsertElemDblClk(eDbc, tS)        begin return( replace( eDbc, 5, tS ));    end;
  149. task InsertSetAttribute(eDbc, tS)    begin return( replace( eDbc, 6, tS ));    end;
  150.  
  151. #########################################################################
  152. #                    PalettePicker(elemStruct) 
  153. #========================================================================
  154. # Author:            DM
  155. # Description:        Dispatches selection request to palette handlers.  
  156. # Parameters:        elemStruct:= Structure containing element info
  157. #                                         Only the first 3 elements are required.
  158. #                            kInWindPal := 1;
  159. #                            kIsWindPal := 2;
  160. #                            kPopUpPal := 4;
  161. #
  162. # Return Values:    1 -  OK
  163. #                        0 - error
  164. # Examples:            PalettePicker(elemStruct);
  165. #========================================================================
  166. # History:
  167. # KTA    8/24/93        TCS stack parity check
  168. # KTA    3/16/94        Moved TCS calls to tool selection routines.
  169. #########################################################################
  170. TASK PalettePicker(elemStruct := {}, ObjectNumber := 0) 
  171. begin
  172.     if (global gDebugFlag)
  173.         Println "----- PalettePicker() - Palette.lib --------";
  174.     global kPalDocWind, kPalWind, kPopUpPal, kMenuItemPopUpPal,gPaletteList;
  175.     
  176.     thePalNum := GetPalNum(elemStruct);            # get the palette number
  177.     thePalette := gPaletteList[thePalNum];        # get the palette
  178.     thePalType := GetPalType(thePalette);            # get the palette type
  179.     
  180.     if (TypeOF(thePalNum) = 'list')                    #### Direct Coordinate Tools
  181.     begin
  182.         returnVal := SelFromCoord(elemStruct,ObjectNumber);    # no palette only coordinates
  183.         if (returnVal)
  184.             returnVal := elemStruct;
  185.     end;
  186.     else if (thePalType = kPalDocWind)                ##### Palette in a Document Window
  187.         returnVal := SelFromDocWind(elemStruct, ObjectNumber);
  188.     else if (thePalType = kPalWind)                     ##### Palette within a seperate window
  189.         returnVal := SelFromPalWind(elemStruct, ObjectNumber);
  190.     else if (thePalType = kPopUpPal)                 ##### Popup Palette
  191.         returnVal := SelFromPopUp(elemStruct, ObjectNumber);
  192.     else if (thePalType = kMenuItemPopUpPal)         ##### MenuItemPopUp Palette
  193.         returnVal := SelFromMenuItemPopUp(elemStruct, ObjectNumber);
  194.     else 
  195.     begin
  196.         LogStr("No selection function declared for palette type {thePalType}",2);
  197.         returnVal := 0;
  198.     end;
  199.     
  200.     return(returnVal);        #Return what sub routines return
  201. end;    
  202.     
  203.     
  204. #########################################################################
  205. #                    CalcOffset(elemStruct) 
  206. #========================================================================
  207. # Author:            KTA
  208. # Description:        Calculates tool offsets based on palette info.  
  209. # Parameters:        elemStruct:= structure containing element info
  210. # Return Values:    toolOffset:= {x,y}
  211. #                        0 - error
  212. # Examples:            CalcOffset(elemStruct);
  213. #========================================================================
  214. # History:
  215. # KTA 9/19/94    Added a rewrite by Michael Press plus a fix when a single column
  216. #                    of tools for kPalDocWind,kPalWind.
  217. # ML    11/13/95    add left margin support for kPalWind
  218. # ML    12/6/95    Card(theRect) < 3 should be 4
  219. # ML    12/8/95    revise for single row of tools
  220. # JC   2/6/96  Changed TheWindow.r to TheWindow.b.
  221. #########################################################################
  222. task CalcOffset(elemStruct)
  223. begin
  224.     global gPaletteList, kPopUpPal, kMenuItemPopUpPal, kPalDocWind, kPalWind;
  225.  
  226.     #LogStr("Calculating tool offset");
  227.     thePalNum := GetPalNum(elemStruct);
  228.     thePalette := gPaletteList[thePalNum];
  229.     thePalType := GetPalType(thePalette);
  230.     elemNum := GetElemNum(elemStruct);
  231.     theRect := GetPalRect(thePalette);
  232.     theOffsets := GetPalOffsets(thePalette);
  233.     theMatrix := GetPalMatrixSize(thePalette);
  234.     headerHeight := 0;
  235.     leftMargin := 0;
  236.  
  237.     xOffset := theOffsets[1];
  238.     yOffset := theOffsets[2];
  239.     elemsAcross := theMatrix[1];
  240.     elemsDown := theMatrix[2];
  241.  
  242.     if ((Card(theRect) < 4))    # kPalWind
  243.     begin                                            # be a seperate palette window
  244.         if (theRect[2])
  245.             headerHeight := theRect[2];
  246.         if (theRect[3])
  247.             leftMargin := theRect[3];
  248.         
  249.         theWindow := Findwindow(theRect[1]);
  250.         if (TheWindow)
  251.             theRect := TheWindow.b;
  252.     end;
  253.  
  254.     elemTemp := elemNum-1;    
  255.     qTemp := elemTemp / elemsAcross;
  256.     rTemp := ( elemTemp ) mod elemsAcross;
  257.     xMove := rtemp * xOffset;
  258.     yMove := qtemp * yOffset;
  259.     
  260.     xAbsoluteOffSet := theRect[1] + leftMargin;
  261.     yAbsoluteOffSet := theRect[2] + headerHeight;
  262.  
  263.     if (thePalType = kPopUpPal) or (thePalType = kMenuItemPopUpPal)    #To handle popup palettes when selecting from a 
  264.     begin                                                            # palette you begin at the correct location.
  265.         xAbsoluteOffSet := 0;
  266.         yAbsoluteOffSet := 0;
  267.     end;
  268.     if (elemsAcross = 1)
  269.     begin
  270.         xAbsoluteOffSet := 0;
  271.         if (xOffset = 0) and ((thePalType = kPalDocWind) or (thePalType = kPalWind))    
  272.             xOffset := theRect[1] + theRect[3];                                            
  273.     end;    
  274.     if (elemsDown = 1)
  275.     begin
  276.         yAbsoluteOffSet := 0;
  277.         if (yOffset = 0) and ((thePalType = kPalDocWind) or (thePalType = kPalWind))    
  278.             yOffset := theRect[2] + theRect[4];                                            
  279.     end;    
  280.     xMove := xMove + xAbsoluteOffSet + xOffset/2;
  281.     yMove := yMove + yAbsoluteOffSet + yOffset/2;
  282.     
  283.     
  284.     If((xMove) or (yMove))
  285.         returnVal := {xMove, yMove};
  286.     else
  287.         returnVal := 0;
  288.     #Println "This is the CalcOffset returnVal - ", returnVal;
  289.     return(returnVal);
  290. end; # CalcOffset()
  291.  
  292. #########################################################################
  293. #                    SelFromDocWind(elemStruct) 
  294. #========================================================================
  295. # Author:            DM
  296. # Description:        Selects tools from palettes that are builtin to doc windows.  
  297. #                        You can also specify a Rect in Global coordinates outside
  298. #                        the document window. 
  299. # Parameters:        elemStruct
  300. #                        pObjectNumber - Number to identify the elements required for
  301. #                                            to draw the object.
  302. # Return Values:    1 -  OK
  303. #                        0 - error
  304. # Examples:            SelFromDocWind(elemStruct);
  305. #========================================================================
  306. # History:
  307. # KTA    3/15/94    Added TCS support
  308. #########################################################################
  309. TASK SelFromDocWind(elemStruct, pObjectNumber)
  310. begin
  311.     global gPaletteList;
  312.     windSpecifier := 0;
  313.     thePalNum := GetPalNum(elemStruct);
  314.     thePalette := gPaletteList[thePalNum];
  315.     theRect := GetPalRect(thePalette);
  316.     theElemNum :=     GetElemNum(elemStruct);            # get the elem number
  317.     theElemName := GetElemName(elemStruct);        # get the elem name
  318.  
  319.     theToolDescriptor := "PaletteNumber : {thePalNum} / ToolNumber : {theElemNum} / ToolName : {theElemName}";
  320.     
  321.     LogStr("Preparing to select the '{theElemName}' tool / number - '{theElemNum}' from Palette '#{thePalNum}' which is contained within a document window",4);
  322.     TCSStart({ 1, global kTCSetSelectFromPalette },"Select from a Palette in document window");        # Start TCS
  323.     whereMove := CalcOffset(elemStruct);
  324.     if(whereMove)
  325.     begin
  326.         xMove := whereMove[1];
  327.         yMove := whereMove[2];
  328.         temp := global gDisableAllLogging;
  329.         if not(global gDebugFlag)
  330.             gDisableAllLogging := 1;
  331.         if (Card(theRect) = 4) 
  332.             MoveMouse(xMove, yMove, 1,    2); # Select Tool/Absolute Coordinates
  333.         else if(Card(theRect) = 5)
  334.         begin
  335.             windSpecifier := theRect[5];
  336.             MoveRelativeToWindow(xMove, yMove, windSpecifier,    2); # Select Tool/Relative to doc window
  337.         end;
  338.         gDisableAllLogging := temp;
  339.         returnVal := 1;
  340.     end;
  341.     else
  342.         returnVal := 0;
  343.     
  344.     TCSEnd({ 1, global kTCSetSelectFromPalette }, returnVal,,pObjectNumber,theToolDescriptor);
  345.     return(returnVal);
  346. end;
  347. #########################################################################
  348. #                    SelFromPalWind(elemStruct) 
  349. #========================================================================
  350. # Author:            DM
  351. # Description:        Selects tools from palettes that are windows.  
  352. # Parameters:        elemStruct:= structure containing element info
  353. #                        pObjectNumber - Number to identify the elements required for
  354. #                                            to draw object.
  355. # Return Values:    1 -  OK
  356. #                        0 - error
  357. # Examples:            SelFromPalWind(elemStruct);
  358. #========================================================================
  359. # History:
  360. # KTA    3/15/94    Added TCS support
  361. #########################################################################
  362. TASK SelFromPalWind(elemStruct, pObjectNumber)
  363. begin
  364.     returnVal := 0;
  365.     
  366.     thePalNum := GetPalNum(elemStruct);            # get the palette number    
  367.     theElemName := GetElemName(elemStruct);        # get the elem name
  368.     theElemNum :=     GetElemNum(elemStruct);            # get the elem number
  369.     theToolDescriptor := "PaletteNumber : {thePalNum} / ToolNumber : {theElemNum} / ToolName : {theElemName}";
  370.     
  371.     LogStr("Preparing to select the '{theElemName}' tool / number - '{theElemNum}' from Palette '#{thePalNum}' which is a separate window",4);
  372.     TCSStart({ 2, global kTCSetSelectFromPalette },"Select from a Palette Window");        # Start TCS
  373.     whereMove := CalcOffset(elemStruct);
  374.     if(whereMove)
  375.     begin
  376.         xMove := whereMove[1];
  377.         yMove := whereMove[2];
  378.         temp := global gDisableAllLogging;
  379.         if not(global gDebugFlag)
  380.             gDisableAllLogging := 1;
  381.         MoveMouse(xMove, yMove, ,    2);    # Select tool
  382.         gDisableAllLogging := temp;
  383.         returnVal := 1;
  384.     end;
  385.     else
  386.         returnVal := 0;
  387.     
  388.     TCSEnd({ 2, global kTCSetSelectFromPalette }, returnVal,,pObjectNumber,theToolDescriptor);
  389.     return(returnVal);
  390. end;
  391.  
  392. #########################################################################
  393. #                    SelFromCoord(elemStruct, ObjectNumber) 
  394. #========================================================================
  395. # Author:            KTA
  396. # Description:        Selects tools from coodinates either global or relative to the 
  397. #                        front window.
  398. # Parameters:        elemStruct:= structure containing tool info
  399. # Return Values:    Returns what is returned by MoveRelativeToWindow() or MoveMouse()
  400. # Examples:            SelFromCoord(elemStruct);
  401. #========================================================================
  402. # History:
  403. # KTA    8/3/93        There was no returnVal for absolute coordinate moves.
  404. # KTA    8/24/93        TCS stack parity check
  405. #########################################################################
  406. TASK SelFromCoord(elemStruct,ObjectNumber)
  407. begin
  408.     temp := global gDisableAllLogging;
  409.     if not(global gDebugFlag)
  410.         gDisableAllLogging := 1;
  411.  
  412.         theElemName := GetElemName(elemStruct);    # get the elem name
  413.         theCoord := GetPalNum(elemStruct);            # get the palette number
  414.         theElemNum := GetElemNum(elemStruct);            # get the elem number
  415.         xCoor := theCoord[1];
  416.         yCoor := theCoord[2];
  417.         RelativeFlag := theCoord[3];
  418.     
  419.         theToolDescriptor := "ToolCoords : {theCoord} / ToolNumber : {theElemNum} / ToolName : {theElemName}";
  420.  
  421.         TCSStart({ 4, global kTCSetSelectFromPalette },"Select from Coordinates");        # Start TCS
  422.  
  423.         Str := "Selecting the '{theElemName}' tool from coordinates ∂({xCoor},{yCoor}∂)";
  424.         if (RelativeFlag) # RelativeToWindow
  425.         begin
  426.             returnVal := MoveRelativeToWindow(xCoor, yCoor, ,2,,RelativeFlag);
  427.             str1:= " which are relative to the front window";
  428.         end;
  429.         else    # Absolute Coordinates 
  430.         begin
  431.             MoveMouse(xCoor, yCoor, , 2);
  432.             returnVal:= 1;
  433.             str1:= " which are absolute coordinates";
  434.         end;
  435.         # Tool has been Selected
  436.         
  437.         Str := Str + str1;
  438.         gDisableAllLogging := temp;
  439.         LogStr(Str);
  440.         if (returnVal)
  441.             TCSReturn :=1;
  442.         else
  443.             TCSReturn :=0;
  444.         TCSEnd({ 4, global kTCSetSelectFromPalette }, TCSReturn,,ObjectNumber,theToolDescriptor);
  445.         
  446.         return(returnVal);
  447. end;
  448. #########################################################################
  449. #                    SelFromPopUp(elemStruct, pObjectNumber) 
  450. #========================================================================
  451. # Author:            DM
  452. # Description:        Selects tools from palettes that pop up.  
  453. # Parameters:        elemStruct:= structure containing element info
  454. #                        pObjectNumber - Number to identify the elements required for
  455. #                                            to draw the object.
  456. # Return Values:    1 -  OK
  457. #                        0 - error
  458. # Examples:            SelFromPopUp(elemStruct);
  459. #========================================================================
  460. # History:
  461. # KTA    3/15/94    Added TCS support
  462. # KTA    9/19/94    Turn gTargetCheck off so won't match the target when mouseDown.
  463. # ML    11/29/94    Added exception handling support
  464. # ML    12/12/94    Removed gTargetcheck
  465. # ML    11/9/95    Removed mismatched else after global gDebugFlag
  466. # ML    12/19/95 add global hook
  467. #########################################################################
  468. TASK SelFromPopUp(elemStruct, pObjectNumber)
  469. begin
  470.     global gPaletteList, gAppVerify;
  471.     thePalNum := GetPalNum(elemStruct);
  472.     thePalette := gPaletteList[thePalNum];
  473.     theRect := GetPalRect(thePalette);
  474.     theElemNum :=     GetElemNum(elemStruct);            # get the elem number
  475.     theElemName := GetElemName(elemStruct);        # get the elem name
  476.     theToolDescriptor := "PaletteNumber : {thePalNum} / ToolNumber : {theElemNum} / ToolName : {theElemName}";
  477.  
  478.     LogStr("Preparing to select the '{theElemName}' tool / number - '{theElemNum}' from Palette '#{thePalNum}' which is a popup palette",4);
  479.     TCSStart({ 3, global kTCSetSelectFromPalette },"Select from a PopUp Palette");        # Start TCS
  480.  
  481.     if (global gDebugFlag)
  482.         println "This is the ElemStruct", elemStruct;
  483.     
  484.     # if we are moving with absolute coordinates the rect should have 4 items
  485.     if (Card(theRect) = 5)        # IF 
  486.         windSpecifier := theRect[5];
  487.     
  488.     whereMove := CalcOffset(elemStruct);
  489.     if(whereMove)
  490.     begin
  491.         xMove := whereMove[1];
  492.         yMove := whereMove[2];
  493.         returnVal := 1;
  494.     end;
  495.     else
  496.         returnVal := 0;
  497.  
  498.     tempSpeed := MouseSpeed(5);
  499.     temp := global gDisableAllLogging;
  500.     if not(global gDebugFlag)
  501.         gDisableAllLogging := 1;
  502.  
  503.     if (isUndefined(windSpecifier))
  504.         MoveMouse(theRect[1], theRect[2], 1,    0);      # move to pop-point
  505.     else 
  506.         MoveRelativeToWindow(theRect[1], theRect[2], windSpecifier,    0);      # move to pop-point
  507.     
  508.     tempAppVerify := gAppVerify;
  509.     gAppVerify := 0;
  510.     _PressMouse();
  511.     wait(2);
  512.     MoveMouse(theRect[3] - theRect[1], theRect[4] - theRect[2], 0,    0);    # press mouse - move to topLeft item
  513.     MoveMouse(xMove, yMove, 0,    0);                # move to item and release
  514.     if (global gSelFromPopUpHook)
  515.         call (gSelFromPopUpHook, elemStruct, pObjectNumber);
  516.     _ReleaseMouse();
  517.     gAppVerify := tempAppVerify;
  518.     gDisableAllLogging := temp;
  519.     MouseSpeed(tempSpeed);
  520.     
  521.     TCSEnd({ 3, global kTCSetSelectFromPalette }, returnVal,,pObjectNumber,theToolDescriptor);
  522.  
  523.     return(returnVal);
  524. end;
  525.  
  526. #########################################################################
  527. #                    SelFromMenuItemPopUp(elemStruct) 
  528. #========================================================================
  529. # Author:            KTA
  530. # Description:        Selects tools from palettes that pop up when selecting a 
  531. #                        menuItem.  
  532. # Parameters:        elemStruct:= structure containing element info
  533. #                        pObjectNumber - Number to identify the elements required for
  534. #                                            to draw the object.
  535. # Return Values:    1 -  OK
  536. #                        0 - error
  537. # Examples:            SelFromMenuItemPopUp(elemStruct);
  538. #========================================================================
  539. # History:
  540. # KTA    3/15/94    Added TCS support
  541. # KTA    9/19/94    Turn gTargetCheck off so won't match the target when mouseDown.
  542. # ML    11/29/94    Added exception handling support
  543. # ML    12/12/94    Removed gTargetcheck
  544. # ML    11/9/95    Removed mismatched else after global gDebugFlag
  545. # ML    12/18/95 Move to left first, then top of palette for maintain selection
  546. # ML    12/19/95 add global hook
  547. #########################################################################
  548. TASK SelFromMenuItemPopUp(elemStruct, pObjectNumber)
  549. begin
  550.     global gPaletteList, gAppVerify;
  551.     thePalNum := GetPalNum(elemStruct);
  552.     thePalette := gPaletteList[thePalNum];
  553.     theRect := GetPalRect(thePalette);
  554.     theElemNum :=     GetElemNum(elemStruct);            # get the elem number
  555.     theElemName := GetElemName(elemStruct);        # get the elem name
  556.     theToolDescriptor := "PaletteNumber : {thePalNum} / ToolNumber : {theElemNum} / ToolName : {theElemName}";
  557.  
  558.     LogStr("Preparing to select the '{theElemName}' tool / number - '{theElemNum}' from Palette '#{thePalNum}' which is a menuItem popup palette",4);
  559.     TCSStart({ 5, global kTCSetSelectFromPalette },"Select from a MenuItemPopUp Palette");        # Start TCS
  560.  
  561.     if (global gDebugFlag)
  562.         println "This is the ElemStruct", elemStruct;
  563.     
  564.     # if we are moving with absolute coordinates the rect should have 6 items
  565.     if (Card(theRect) = 7)        # IF 
  566.         windSpecifier := theRect[7];
  567.     
  568.     whereMove := CalcOffset(elemStruct);
  569.     if(whereMove)
  570.     begin
  571.         xMove := whereMove[1];
  572.         yMove := whereMove[2];
  573.         returnVal := 1;
  574.     end;
  575.     else
  576.         returnVal := 0;
  577.  
  578.     tempSpeed := MouseSpeed(5);
  579.     temp := global gDisableAllLogging;
  580.     if not(global gDebugFlag)
  581.         gDisableAllLogging := 1;
  582.  
  583.     if (isUndefined(windSpecifier))
  584.     begin
  585.         MoveMouse(theRect[1], theRect[2], 1,    0);      # move to pop-point
  586.         MoveMouse(theRect[3], theRect[4], 1,    3);      # move to menuItem pop-point
  587.     end;
  588.     else 
  589.     begin
  590.         MoveRelativeToWindow(theRect[1], theRect[2], windSpecifier,    0);      # move to pop-point
  591.         MoveRelativeToWindow(theRect[3], theRect[4], windSpecifier,    3);      # move to menuItem pop-point
  592.     end;
  593.  
  594.     
  595.     tempAppVerify := gAppVerify;
  596.     gAppVerify := 0;
  597.     _PressMouse();
  598.     wait(2);
  599.     MoveMouse(theRect[5] - theRect[3], 0, 0,    0);    # press mouse - move to Left item
  600.     MoveMouse(0, theRect[6] - theRect[4], 0,    0);    # press mouse - move to top item
  601.     MoveMouse(xMove, yMove, 0,    0);                # move to item and release
  602.     if (global gSelFromMenuItemPopUpHook)
  603.         call (gSelFromMenuItemPopUpHook, elemStruct, pObjectNumber);
  604.     _ReleaseMouse();
  605.     gAppVerify := tempAppVerify;
  606.     gDisableAllLogging := temp;
  607.     MouseSpeed(tempSpeed);
  608.     
  609.     TCSEnd({ 5, global kTCSetSelectFromPalette }, returnVal,,pObjectNumber,theToolDescriptor);
  610.  
  611.     return(returnVal);
  612. end;
  613.  
  614. #########################################################################
  615. #                        GetRandomElement()
  616. #========================================================================
  617. # Author:        DM 
  618. # Description:    
  619. # Parameters:    palStruct
  620. # Returns:        
  621. #========================================================================
  622. # History:
  623. #
  624. #########################################################################
  625. TASK GetRandomElement(palStruct) begin
  626.     if (global gDebugFlag)
  627.         Println "----- GetRandomElement() - Palette.lib --------";
  628.  
  629.     theMatrix := GetPalMatrixSize(palStruct);
  630.     numCells := theMatrix[1]*theMatrix[2];
  631.     
  632.     elemNum := random(1, numCells);
  633.     return elemNum;
  634. end; # GetRandomElement()
  635.  
  636.  
  637.